/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.articles.importFromLn.domain;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Martin Řehánek (rehan@mzk.cz)
 */
public enum Language {

    cz,
    de,
    lat,
    unknown;
    private static final Map<String, Language> nameMap;

    static {
        nameMap = new HashMap<String, Language>();
        nameMap.put("de", de);
        nameMap.put("ger", de);
        nameMap.put("cs", de);
        nameMap.put("cz", de);
        nameMap.put("lat", lat);
    }

    public String toIso639_2b() {
        switch (this) {
            case cz:
                return "cze";
            case de:
                return "ger";
            case lat:
                return "lat";
            default:
                return null;
        }
    }

    public String toIso639_3() {
        switch (this) {
            case cz:
                return "ces";
            case de:
                return "deu";
            case lat:
                return "lat";
            default:
                return null;
        }
    }

    public String toRfc4646() {
        switch (this) {
            case cz:
                return "cs-CZ";
            case de:
                return "de-CZ";
            default:
                return null;
        }
    }

    /**
     *
     * @param languageStr string to be parsed
     * @return Language (Language.unknown if cannot parse)
     */
    public static Language parseLanguage(String languageStr) {
        Language mapValue = nameMap.get(languageStr);
        if (mapValue != null) {
            return mapValue;
        } else {
            return unknown;
        }
    }
}
